/*
 * student_send_client.c
 *
 *  Created on: Nov 4, 2012
 *      Author: lakshmanas
 */
#include<unistd.h>
#include "mq_interface.h"

void
mq_send_prog_1(char *host)
{
        CLIENT *clnt;
        int  *result_1;
        Msg_t  msg_1=(Msg_t)malloc(sizeof(Message));
        printf("Enter student info to send to Advisor for course clearance \n");
        //scanf("%d %s %d %s %d %s",&msg_1->student_id,msg_1->student_name,&msg_1->advisor_id,msg_1->advisor_name,&msg_1->course_id,msg_1->course_name);
        //default source is student
//        msg_1->source="student";
        //1 means needs clearance, 0 means cleared
//        msg_1->clearance=1;

        msg_1->source="student";
        msg_1->student_id=1;
        msg_1->student_name="student1";
        msg_1->course_id=5434;
        msg_1->course_name="OS-2";
        msg_1->clearance=1;

#ifndef DEBUG
        clnt = clnt_create (host, MQ_SEND_PROG, MQ_PROG_VERS, "udp");
        if (clnt == NULL) {
                clnt_pcreateerror (host);
                exit (1);
        }
#endif

        result_1 = sendmsg_1(&msg_1, clnt);
        if (result_1 == (int *) NULL) {
            //clnt_perror (clnt, "call failed");
        	printf("Student course approval message sent unsuccessful \n");
        }
        else
            printf("Student course approval message Sent successful \n");
        	printf("Source    : %s  \n"
        		"Student ID: %d  Name :%s \n"
        		"Course Id : %d  Name :%s \n"
        		"clearance : %d \n",
        		msg_1->source,msg_1->student_id,msg_1->student_name,msg_1->course_id,msg_1->course_name,msg_1->clearance);
#ifndef DEBUG
        clnt_destroy (clnt);
#endif
}


int main (int argc, char *argv[])
{
        char *host;
        host = "localhost";
        mq_send_prog_1 (host);
        exit (0);
}

